package geekbang.single;

import java.io.FileWriter;

/**
 * @author xuyanqing
 * @description 单例模式
 * @date 2025-10-11 9:21
 * @creed where there is a will,there is a way. yx
 */

public class Logger {
    private FileWriter fileWriter;
    private static final Logger instance = new Logger();

    static Logger getInstance() {
        return instance;
    }

    private Logger() {
        try {
            fileWriter = new FileWriter("D:\\log.txt", true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void log(String message) {
        try {
            fileWriter.write(message);
            fileWriter.write("\r\n");
            fileWriter.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
